package org.neurone.userspace.userinfo.impl;

import java.util.List;

import org.neurone.domain.UserInfo;
import org.neurone.domain.alter.UserInfoAlter;
import org.neurone.domain.persistence.UserInfoPersistence;
import org.neurone.userspace.dao.UserInfoDao;
import org.neurone.userspace.userinfo.UserMgr;
import org.neurone.util.criteria.CriteriaOperator;
import org.neurone.util.criteria.impl.CriteriaKeyValue;

public class UserMgrLocal implements UserMgr {

	private UserInfoDao userInfoDao;
	
	
	public UserInfoDao getUserInfoDao() {
		return userInfoDao;
	}

	public void setUserInfoDao(UserInfoDao userInfoDao) {
		this.userInfoDao = userInfoDao;
	}

	@Override
	public void delete(Long userID) {
		userInfoDao.deleteUser(userID);
	}

	@Override
	public UserInfo find(Long userID) {
		return userInfoDao.find(userID);
	}

	@Override
	public List<UserInfo> findAll(int pageSize, int pageIndex) {
		return userInfoDao.search(null, pageSize, pageIndex);
	}

	@Override
	public Long newUser(UserInfo userInfo) {
		return userInfoDao.newUser(userInfo);
	}

	@Override
	public List<UserInfo> searchByRealName(String realName, int pageSize,
			int pageIndex) {
		return userInfoDao.search(new CriteriaKeyValue("realName", CriteriaOperator.LIKE, realName),pageSize, pageIndex);
	}

	@Override
	public List<UserInfo> searchByUserName(String userName, int pageSize,
			int pageIndex) {
		return userInfoDao.search(new CriteriaKeyValue("userName", CriteriaOperator.LIKE, userName),pageSize, pageIndex);
	}

	@Override
	public UserInfo find(String userName) {
		List<UserInfo> userList = searchByUserName(userName, 0, 0);
		
		if((userList != null) && (userList.size() >0))
		{
			return userList.get(0);
		}
		
		return null;
	}

}
